
package com.wyzz.hr.action;

import java.util.List;
import org.apache.axis.utils.StringUtils;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.IPerfcritsBO;
import com.wyzz.hr.bo.IPerfcrittypeBO;
import com.wyzz.hr.pojo.Perfcrits;

public class ManagerPerfcrits extends BaseAction {

	public ManagerPerfcrits() {
	}

	public String execute() throws Exception {
		return "success";
	}

	public String addPerfcritsInit() {
		if (StringUtils.isEmpty(critsId)) {
			perfcrits = new Perfcrits();
		} else {
			IPerfcritsBO perfcritsBo = (IPerfcritsBO) getBean("perfcritsBO");
			perfcrits = perfcritsBo.loadObjectById(critsId);
		}
		initDrawList();
		return "success";
	}

	public String addPerfcrits() {
		String mes = null;
		IPerfcritsBO perfcritsBo = (IPerfcritsBO) getBean("perfcritsBO");
		if (StringUtils.isEmpty(critsId)) {
			Integer tempSort = perfcritsBo.getMaxSortId(perfcrits.getPcPctId()
					.getPctId());
			String tempName = perfcrits.getPcName().trim();
			String noteStr = perfcrits.getPcDesc().trim();
			perfcrits.setPcName(tempName);
			perfcrits.setPcDesc(noteStr);
			perfcrits.setPcSortId(tempSort);
			perfcrits.setPcId(null);
			mes = "\u6DFB\u52A0\u8003\u6838\u6307\u6807\u6210\u529F\uFF01";
		} else {
			mes = (new StringBuilder()).append(
					"\u4FEE\u6539\u8003\u6838\u6307\u6807\u201C").append(
					perfcrits.getPcName()).append("\u201D\u6210\u529F\uFF01")
					.toString();
		}
		perfcritsBo.saveObject(perfcrits);
		addSuccessInfo(mes);
		perfcrits = null;
		return "success";
	}

	public String deletePerfcrits() {
		if (StringUtils.isEmpty(critsId))
			return "error";
		IPerfcritsBO perfcritsBo = (IPerfcritsBO) getBean("perfcritsBO");
		String tempStr = perfcritsBo
				.deleteObjectByIds(new String[] { critsId });
		if (!"success".equals(tempStr)) {
			addErrorInfo(tempStr);
			return "success";
		} else {
			addSuccessInfo("\u5220\u9664\u6210\u529F\uFF01");
			return "success";
		}
	}

	public String changeCritsStatus(String id, Integer status) {
		if (StringUtils.isEmpty(id)) {
			return "error";
		} else {
			IPerfcritsBO perfcritsBo = (IPerfcritsBO) getBean("perfcritsBO");
			Perfcrits tempPerfcrits = perfcritsBo.loadObjectById(id);
			tempPerfcrits.setPcStatus(status);
			perfcritsBo.saveObject(tempPerfcrits);
			return "success";
		}
	}

	private void initDrawList() {
		IPerfcrittypeBO perfcrittypeBo = (IPerfcrittypeBO) getBean("perfcrittypeBO");
		perfcrittypeList = perfcrittypeBo.loadAll();
	}

	public String critsDeleteBatch() {
		if (StringUtils.isEmpty(critsIds)) {
			addErrorInfo("\u6CA1\u6709\u9700\u8981\u5220\u9664\u7684\u8003\u6838\u6307\u6807\uFF01");
			return "success";
		}
		String tempArray[] = critsIds.split(";");
		IPerfcritsBO perfcritsBo = (IPerfcritsBO) getBean("perfcritsBO");
		String tempStr = perfcritsBo.deleteObjectByIds(tempArray);
		if (!"success".equals(tempStr)) {
			addErrorInfo(tempStr);
			return "success";
		} else {
			addSuccessInfo("\u5220\u9664\u6210\u529F\uFF01");
			return "success";
		}
	}

	public String checkNameDuplicate(String name) {
		if (StringUtils.isEmpty(name))
			return "\u8003\u6838\u6307\u6807\u7684\u540D\u5B57\u4E0D\u53EF\u4EE5\u4E3A\u7A7A\uFF01";
		IPerfcritsBO perfcritsBo = (IPerfcritsBO) getBean("perfcritsBO");
		boolean tempFlag = perfcritsBo.checkObjectByName(name);
		if (!tempFlag)
			return "success";
		else
			return "\u8BE5\u8003\u6838\u6307\u6807\u5728\u7CFB\u7EDF\u4E2D\u5DF2\u7ECF\u5B58\u5728\uFF01";
	}

	public List getPerfcrittypeList() {
		return perfcrittypeList;
	}

	public void setPerfcrittypeList(List perfcrittypeList) {
		this.perfcrittypeList = perfcrittypeList;
	}

	public Perfcrits getPerfcrits() {
		return perfcrits;
	}

	public void setPerfcrits(Perfcrits perfcrits) {
		this.perfcrits = perfcrits;
	}

	public String getCritsId() {
		return critsId;
	}

	public void setCritsId(String critsId) {
		this.critsId = critsId;
	}

	public String getCritsStatus() {
		return critsStatus;
	}

	public void setCritsStatus(String critsStatus) {
		this.critsStatus = critsStatus;
	}

	public String getCritsIds() {
		return critsIds;
	}

	public void setCritsIds(String critsIds) {
		this.critsIds = critsIds;
	}

	private static final long serialVersionUID = 1L;
	private List perfcrittypeList;
	private Perfcrits perfcrits;
	private String critsId;
	private String critsStatus;
	private String critsIds;
}
